package com.globallogic.dmytro_zakharenko.university;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

import com.globallogic.dmytro_zakharenko.university.enums.LessonNames;
import com.globallogic.dmytro_zakharenko.university.lessons.Lesson;
import com.globallogic.dmytro_zakharenko.university.person.AdministrationPersonal;
import com.globallogic.dmytro_zakharenko.university.person.Student;
import com.globallogic.dmytro_zakharenko.university.person.Teacher;

public class Universitet {
	
	private final static double TEACHER_SALARY = 1321;
	private final static double ADMIN_SALARY = 800;
	private final static double STUDENT_SCHOLARSHIP = 123;
	
	public static void main(String[] args) throws Exception {	
		
		// *******************************************************************
		// 	LESSON, SEMINAR, LECTURE
		// *******************************************************************	
		@SuppressWarnings("unused")
		ArrayList<Lesson> lessons = createLessons();
		
		// *******************************************************************
		// 	STUDENTS, TEACHER, ADMINISTRATION PERSONAL 
		// *******************************************************************
		Set<Student> studentsOfFirstCourse = enroleFirstCourseStudents();
		
		Set<Teacher> teachers = enroleTeachers();
		setLessonsForTeachers(teachers.toArray(new Teacher[0]));
		
		@SuppressWarnings("unused")
		Set<AdministrationPersonal> personal = enrolePersonal();
		
		// *******************************************************************
		// 	CURRICULUM
		// *******************************************************************
		Curriculum curriculum = new Curriculum(teachers);
		
		// *******************************************************************
		// 	COURSE1
		// *******************************************************************
		Course firstCourse = new Course(curriculum.getFirstCourseLessons());
		firstCourse.enrollStudents(studentsOfFirstCourse);
		firstCourse.enrollTeachers(curriculum.getFirstCourseTeachers());
		
		// *******************************************************************
		// 	SCHEDULE
		// *******************************************************************
		Schedule schedule = new Schedule();
		String[][] s = schedule.getSchedule();
		
		// *******************************************************************
		// 	PRINT INFORMATION
		// *******************************************************************
		Set<Teacher> firstCourseTeacher = firstCourse.getEnrolledTeachers();
		
		printSchedule(s);
		
		printFirstCouresTeachers(firstCourseTeacher.toArray(new Teacher[0]));
	}
	
	/**
     * creates students objects 
     *
     *@return Student[]
     */
	public static Set<Student> enroleFirstCourseStudents() {
		Set<Student> studentsOfFirstCourse = new HashSet<Student>();
		
		studentsOfFirstCourse.add(new Student("Lavender",	"Brown", 1980, "London", STUDENT_SCHOLARSHIP));
		studentsOfFirstCourse.add(new Student("Seamus", "Finnigan", 1980, "Circa", STUDENT_SCHOLARSHIP));
		studentsOfFirstCourse.add(new Student("Hermione", "Granger", 1979, "London", STUDENT_SCHOLARSHIP));
		studentsOfFirstCourse.add(new Student("Neville", "Longbottom", 1980, "London", STUDENT_SCHOLARSHIP));
		studentsOfFirstCourse.add(new Student("Patil",	"Parvati", 1980, "Circa", STUDENT_SCHOLARSHIP));
		studentsOfFirstCourse.add(new Student("Harry",	"Potter", 1980, "London", STUDENT_SCHOLARSHIP));
		studentsOfFirstCourse.add(new Student("Dean",	"Thomas", 1980, "Circa", STUDENT_SCHOLARSHIP));
		studentsOfFirstCourse.add(new Student("Ronald", "Weasley", 1980, "London", STUDENT_SCHOLARSHIP));
		
		return studentsOfFirstCourse;		
	}
	
	/**
     * creates teachers objects 
     *
     *@return Teacher[]
     */
	public static Set<Teacher> enroleTeachers() {
		Set<Teacher> teachers = new HashSet<Teacher>();
		
		teachers.add(new Teacher("Albus", "Dumbledore", 1910, "London", TEACHER_SALARY)); 
		teachers.add(new Teacher("Minerva", "McGonagall", 1910, "Circa", TEACHER_SALARY));
		teachers.add(new Teacher("Pomona",	"Sprout", 1919, "London", TEACHER_SALARY));
		teachers.add(new Teacher("Filius",	"Flitwick", 1920, "London", TEACHER_SALARY));
		teachers.add(new Teacher("Severus", "Snape", 1960, "Circa", TEACHER_SALARY));
		teachers.add(new Teacher("Sybill",	"Trelawney", 1940, "London", TEACHER_SALARY));
		teachers.add(new Teacher("Alastor", "Moody", 1980, "Circa", TEACHER_SALARY));
		teachers.add(new Teacher("Rolanda", "Hooch", 1930, "London", TEACHER_SALARY));
		teachers.add(new Teacher("Horace",	"Slughorn",	1914, "London", TEACHER_SALARY));
		teachers.add(new Teacher("Wilhelmina",	"Grubbly-Plank", 1930, "Circa", TEACHER_SALARY));
		teachers.add(new Teacher("Quirinus", "Quirrell",	1959, "London", TEACHER_SALARY));
		teachers.add(new Teacher("Gilderoy", "Lockhart",	1940, "London", TEACHER_SALARY));
		teachers.add(new Teacher("Dolores", "Umbridge", 1930, "Circa", TEACHER_SALARY));
		
		return teachers;		
	}
	
	/**
     * creates administration personals objects 
     *
     *@return AdministrationPersonal[]
     */
	public static Set<AdministrationPersonal> enrolePersonal() {
		Set<AdministrationPersonal> personal = new HashSet<AdministrationPersonal>();;
		
		personal.add(new AdministrationPersonal("Poppy", "Pomfrey", 1940, "London", ADMIN_SALARY));
		personal.add(new AdministrationPersonal("Argus", "Filch", 1914, "Circa", ADMIN_SALARY));
		personal.add(new AdministrationPersonal("Rubeus", "Hagrid", 1959, "London", ADMIN_SALARY));
		personal.add(new AdministrationPersonal("Irma", "Pince", 1940, "London", ADMIN_SALARY));
		personal.add(new AdministrationPersonal("Charity",	"Burbage", 1942, "Circa", ADMIN_SALARY));
		
		return personal;
	}
	
	/**
     * creates Lessons objects, names for the lessons takes from LessonNames class 
     *
     *@return Lesson[]
     */
	public static ArrayList<Lesson> createLessons() {
		LessonNames.setBasicLessons();
		ArrayList<Lesson> lessons = new ArrayList<Lesson>();
		for (String ls : LessonNames.getLessonsName()) {
			lessons.add(new Lesson(ls));
		}
		
		return lessons;
	}
	
	/**
     * add to existing Teachers objects specified lessons, names for the lessons takes from LessonNames class 
     */
	public static void setLessonsForTeachers(Teacher[] teachers) {
		try {
			int j = 0;
			for (int i = 0; i < teachers.length; i++) {
				ArrayList<String> lessonsForTeacher = new ArrayList<String>();
				lessonsForTeacher.add(LessonNames.getLessonsName()[j]);
				lessonsForTeacher.add(LessonNames.getLessonsName()[2 + j]);
				teachers[i].setLessons(lessonsForTeacher);
				j += 4;
			}
		} catch (ArrayIndexOutOfBoundsException e) {
			System.out.println("The lessons were not initialized. Initialize to default lessons.");
			LessonNames.setBasicLessons();
			setLessonsForTeachers(teachers);
		} 
	}
	
	/**
     * print schedule for all courses
     */
	public static void printSchedule(String[][] s) {
		System.out.println("UNIVERSITY SCHEDULE");
		for(String[] st : s) {
			System.out.println("Day : " + st[0] + "; " + "Time : " + st[1] + "; " + "Lesson : " + st[2] + "; " + "Auditorum : " + st[3] + " ;");
		}
	}
	
	/**
     * print information about teachers of first course
     */
	public static void printFirstCouresTeachers(Teacher[] firstCourseTeacher) {
		System.out.println("TEACHERS OF FIRST COURSE");
		
		for(Teacher t : firstCourseTeacher) {
			System.out.println("Name : " + t.getFirstName() + "; " + "Lessons : " + t.getLessons().toArray(new String[0])[0] + ";  " + t.getLessons().toArray(new String[0])[1] + " ;");
		}	
	}
}
